package net.skyedu.service.manager;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.skyedu.bean.Attendance;
import net.skyedu.dao.UserInfoDao;
/**
 * Messenger use
 * @author Jason
 * @jinxuan07@163.com
 */
public class Spec extends HttpServlet {

	private static final long serialVersionUID = 1684007998573742906L;

	/**
	 * Constructor of the object.
	 */
	public Spec() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=UTF-8");
		doPost(request,response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=UTF-8");
		request.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		
		String tworktime=request.getParameter("tworktime");
		String tclostime=request.getParameter("tclostime");
		String startTime=request.getParameter("startTime");
		String endTime=request.getParameter("endTime");
		String currentPage=request.getParameter("currentPage");
		String sta=request.getParameter("sta");
		String name=request.getParameter("na");
		String attId=request.getParameter("attId");
		
		UserInfoDao ud=new UserInfoDao();
		Attendance att=new Attendance();
		att.setAttworktime(tworktime);
		att.setAttclosingtime(tclostime);
		att.setAttid(Integer.parseInt(attId));
		int num=ud.upTime(att);
		if(num>0){
			request.getRequestDispatcher("Manager?sta="+sta+"&currentPage="+currentPage+"&startTime="+startTime+"&endTime="+endTime+"&username="+name).forward(request, response);
		}else{
			out.print("<script type='text/javascript'>alert('Error:101,Spec!');history.go(-1);</script>");
		}
		
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}
}
